{include file="public/header"}

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form action="" method="post" class="layui-form layui-form-pane">
                {if empty(input('get.copy'))}
                <input type="hidden" value="{$row['id']|default='0'}" name="id" />
                {/if}
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">备注</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="text" name="name" autocomplete="off" class="layui-input" placeholder=""
                                value="{$row.name|default='0'}">
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">下单日期范围</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="text" id="test" name="datas[fwtime]" autocomplete="off" class="layui-input"
                                placeholder="" value="{$row.datas.fwtime|default=''}">
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">状态</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <select name="status" lay-verify="required">
                                <option value="1" {if !empty($row.status) && $row.status==1}selected{/if}>刷单</option>
                                <option value="2" {if !empty($row.status) && $row.status==2}selected{/if}>停止刷单</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">每日总刷单金额</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="number" name="datas[allmoney]" autocomplete="off" class="layui-input"
                                placeholder="" value="{$row.datas.allmoney|default='0'}">
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">单家店铺每日刷单最高金额</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="number" name="datas[money]" autocomplete="off" class="layui-input"
                                placeholder="" value="{$row.datas.money|default=''}">
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">刷单商家(仅显示有配送区域并且已添加服务项目的商家)</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <div class="layui-col-md12">
                                <input type="checkbox" lay-skin="primary" lay-filter="father" title="全选">
                            </div>
                            <div class="layui-col-md12">
                                {foreach $business as $k => $v}
                                <input name="datas[business][]" lay-skin="primary" type="checkbox" value="{$v.id}"
                                    title="{$v.title}" {if !empty($row.datas.business) && in_array($v.id,
                                    $row.datas.business)}checked {/if}>
                                {/foreach}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">用户信息</div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <div class="layui-col-md12">
                            <a class="layui-btn layui-btn-btn layui-btn-sm layui-btn-normal"
                                onclick="addtable()">添加数据</a>
                            <table class="layui-table layui-form" id="table" lay-filter="table">
                                <thead>
                                    <tr>
                                        <td>
                                            <div class="layui-table-cell">用户名</div>
                                        </td>
                                        <td>
                                            <div class="layui-table-cell">手机号</div>
                                        </td>
                                        <td>
                                            <div class="layui-table-cell">住宅和楼号</div>
                                        </td>
                                        <td>
                                            <div class="layui-table-cell">操作</div>
                                        </td>
                                    </tr>
                                </thead>
                                <tbody>
                                    {if !empty($row.datas.user)}
                                    {foreach $row.datas.user as $k => $v}
                                    <tr>
                                        <td><input required="" lay-verify="required" type="text" id="layui-input"
                                                class="layui-input" name="datas[user][{$k}][name]"
                                                value="{$v.name|default=''}">
                                        </td>
                                        <td><input required="" lay-verify="required" type="number" id="layui-input"
                                                class="layui-input" name="datas[user][{$k}][mobile]"
                                                value="{$v.mobile|default=''}">
                                        </td>
                                        <td><input required="" lay-verify="required" type="text" id="layui-input"
                                                class="layui-input" name="datas[user][{$k}][address]"
                                                value="{$v.address|default=''}" placeholder="例:泉塘小区2栋14单元501">
                                        </td>
                                        <td>
                                            <a class="layui-btn layui-btn-danger layui-btn-xs del">删除</a>
                                        </td>
                                    </tr>
                                    {/foreach}
                                    {/if}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    {if empty(input('get.copy'))}
                    <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
                    {else}
                    <button class="layui-btn" lay-submit="" lay-filter="add">复制并添加</button>
                    {/if}
                </div>
            </form>
        </div>
    </div>
    {include file="public/footer"}
    <script src="/static/leyedit/Layui-KnifeZ/layui.all.js"></script>
    <script src="/static/leyedit/ace/ace.js"></script>
    <script>
        function addtable() {
            var i = $('#table tbody tr').length;
            //你要添加的html
            var html = '<tr>' +
                '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="datas[user][' + i + '][name]" value=""></td>' +
                '<td><input required="" lay-verify="required" type="number" id="layui-input" class="layui-input" name="datas[user][' + i + '][mobile]" value=""></td>' +
                '<td><input required="" lay-verify="required" placeholder="例:泉塘小区2栋14单元501" type="text" id="layui-input" class="layui-input" name="datas[user][' + i + '][address]" value=""></td>' +
                '<td><a class="layui-btn layui-btn-danger layui-btn-xs del" >删除</a></td></tr>';
            $(html).appendTo($('#table tbody:last'));
            layui.use(['form'], function () {
                $ = layui.jquery;
                var form = layui.form;
                form.render();
            });
        };
        $('body').on('click', '.del', function () {
            $(this).closest('tr').remove();
        });
        layui.use(['form', 'layer', 'upload', 'upload', 'layedit', 'laydate'], function () {
            $ = layui.jquery;
            var form = layui.form
                , upload = layui.upload
                , element = layui.element
                , laydate = layui.laydate
                , layer = layui.layer
                , layedit = layui.layedit;
            laydate.render({
                elem: '#test'
                , type: 'date'
                , range: '~'
            });
            form.on('checkbox(father)', function (data) {
                console.log(data);
                if (data.elem.checked) {
                    $(data.elem).parent().next('div').find('input').prop("checked", true);
                    form.render();
                } else {
                    $(data.elem).parent().next('div').find('input').prop("checked", false);
                    form.render();
                }
            });
            layedit.set({
                //暴露layupload参数设置接口 --详细查看layupload参数说明
                uploadImage: {
                    url: '/Base/upload_img',
                    accept: 'image',
                    acceptMime: 'image/*',
                    exts: 'jpg|png|gif|bmp|jpeg',
                    size: '100240'
                }
                //右键删除图片/视频时的回调参数，post到后台删除服务器文件等操作，
                //传递参数：
                //图片： imgpath --图片路径
                //视频： filepath --视频路径 imgpath --封面路径
                , calldel: {
                    url: '/Base/upload_img'
                }
                //开发者模式 --默认为false
                , devmode: false
                //插入代码设置
                , codeConfig: {
                    hide: true,  //是否显示编码语言选择框
                    default: 'javascript' //hide为true时的默认语言格式
                }

                , tool: [
                    'strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right'
                ]
                , height: '300px'
            });
            //监听提交
            var infos = layedit.build('infos');
            form.on('submit(add)', function (data) {
                data.field.value = layedit.getContent(infos);
                //发异步，把数据提交给php
                $.ajax({
                    type: 'post',
                    data: data.field,
                    success: function (res) {
                        if (res.status == 0) {
                            layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
                return false;
            });
        });
    </script>